package com.partybuilding.Controller;

import com.partybuilding.domain.ResponseResult;
import com.partybuilding.domain.entity.Admintable;
import com.partybuilding.enums.AppHttpCodeEnum;
import com.partybuilding.expection.SystemException;
import com.partybuilding.service.AdmintableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "用户登入",description="普通用户和后台管理员统一登录接口")
public class AdminController {

    @Autowired
    private AdmintableService admintableService;

    @PostMapping("/login")
    @ApiModelProperty(value = "登录按钮，需传递用户配套相关信息")
    public ResponseResult adminLogin(@RequestBody Admintable admintable){
        if(!StringUtils.hasText(admintable.getUser_name())){
           //提示 必须传递用户名
            throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
        }
        System.out.println(admintable);
        return admintableService.login(admintable);
    }

    @PostMapping("/logout")
    public ResponseResult adminLogout(){
        return admintableService.logout();
    }

    @PostMapping("/regist")
    public ResponseResult regist(Admintable admintable){
        return admintableService.regist(admintable);

    }
}
